var mongoose = require('mongoose')
var settings = require('../settings.js')
var UserModelBuilder = require('../models/UserModelBuilder.js')
var ArticleModelBuilder = require('../models/ArticleModelBuilder.js')
var BetterArticleModelBuilder = require('../models/BetterArticleModelBuilder.js')
var opn  = require('opn')

var db = mongoose.createConnection(settings.host, settings.db)

db.on('error', console.error.bind(console,'数据库连接失败,请确保已经开启mongodb数据库\r\n') )
db.once('open', function () {
  console.log('数据库已连接')
  opn('http://localhost:8080')
})

module.exports = {
  UserModel: UserModelBuilder(db),
  ArticleModel: ArticleModelBuilder(db),
  BetterArticleModel: BetterArticleModelBuilder(db)
}